#include <DHT.h>
// #include "max6675.h" //加载max6675库
#include "stdio.h"
#include "stdlib.h"
#include "U8glib.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
int thermoDO = 4;     //S0
int thermoCS = 2;     //CS
int thermoCLK = 15;    //SCK

#define OLED_DC 16
#define OLED_CS 17
#define OLED_CLK 15
#define OLED_MOSI 2
#define OLED_RESET 4

#define DHT11PIN 13
#define DHTTYPE DHT11


Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
// U8GLIB_SSD1306_128X64 myoled(15, 2, 12, 4);  // SW SPI Com: SCL = 10, SDA = 9, CS = 12, DC = 11,RES=RESET

// DHT mydht(DHT11PIN, DHTTYPE);
// MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);  //建立MAX6675 对象实例
void setup()
{
    Serial.begin(115200);
    Serial.println("start!");
    // mydht.begin();
    // myoled.setFont(u8g_font_osb18);//设置要显示字符的字体
    display.begin(SSD1306_SWITCHCAPVCC);
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.display();
    delay(1000);
    display.clearDisplay();   // clears the screen and buffer
}

void loop()
{
    delay(1000);
    // Serial.print("C = "); 
    // Serial.println(thermocouple.readCelsius());   //串口输出摄氏度
    // float h = mydht.readHumidity();
    // float t = mydht.readTemperature();
    float h =random(1000)/10.0;
    float t =random(1000)/10.0;
    String h_str = "Hum:" + String(h);
    String t_str ="Temp:" +String(t);
    display.clearDisplay();   // clears the screen and buffer
    display.setCursor(0,0);
    display.println(h_str);
    display.println(t_str);
    display.display();
    // myoled.drawStr(0,0,"Hum:");
    // myoled.drawStr(4*8,0,String(h));
    // myoled.drawStr(0,2,"Temp:");
    // myoled.drawStr(5*8,2,String(t));
    Serial.print("Humidity: ");
    Serial.println(h);
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println("C");
}
